from scopt.util.message_types import STRING
from scopt.util import message as msg_util
from scopt.mpu.business.db import transaction
from scopt.mpu.business.demo import inventory_data
from . import message


@message(type='context.tenant.create',
         version='0.1',
         reqd={'tenant_name': STRING(required=True),
               'params': {}},
         resd={'tenant_id': STRING(required=True),
               'tenant_name': STRING(required=True)})
@transaction(['lds/BDS'])
def handle(data_packet):
    db = msg_util.get_db(data_packet)
    db.init_lds(lds='lds/BDS')
    if data_packet['demo']:
        demo_data = [inventory_data.insert]
        db.init_demo_data(demo_data)
    return data_packet
